/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.santi.framework.dictionary.impl;

import com.santi.framework.common.constants.CommonConstants;
import com.santi.framework.dictionary.service.Dictionary;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;



/**
 *
 * @author Prabhat
 */
public class DictionaryFactory {
    
private static DictionaryFactory instance = null;

    private Map<String, Dictionary> dictionary = null;
   
    private DictionaryFactory(){
       dictionary=Collections.synchronizedMap(new HashMap<String, Dictionary>());
    } 
    
     public static DictionaryFactory getInstance() {
       // System.out.println("...............inside LookUpReader getInstance ");
        if (instance == null) {
            instance = new DictionaryFactory();
          // System.out.println("...............INITIALIZATION START.........");
            instance.init();
           //System.out.println("...............INITIALIZATION END........");
        }
        return instance;
    }
     private synchronized void init() {
        try {
            Dictionary odiyaDictionary= new DictionaryImpl("english_odia.dic",CommonConstants.ENGLISH_LANG_CODE);
            dictionary.put(CommonConstants.ENGLISH_LANG_CODE, odiyaDictionary);
        } catch (Exception ex) {
            Logger.getLogger(DictionaryFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
     }
     
     public Dictionary getDictionary(String langCode){
        return dictionary.get(langCode);
     }
     public static void destroyCache(){
        System.out.println("...............Calling.....destroyCache...... ");
        instance=null;
    }
}
